﻿using System;
using System.IO;
using System.Web;

namespace GlobalLib
{
    public class PhotoUpFile
    {
        #region 图片上传处理过程
        /// <summary>
        /// 图片上传处理过程
        /// </summary>
        /// <param name="HttpPostedFile">文件</param>
        /// <param name="FilePath">路径</param>
        /// <returns></returns>
        public static bool TryProcessImage(HttpPostedFile file,out Stream result )
        {
            result = null;
            return false;
            /*
            string response = "1";

            if (file == null)
            {
                response = "800400";
                return response;
            }

            if (!this.isImage(file))
            {
                response = "800411";
                return response;
            }

            this._savePathFile = this.newFile("yyyy-MM");//目录
            string SavafilePath = FilePath + _savePathFile;//   初始化上传目录



            string thefiledir = file.FileName;//获取本地文件路径
            int theFileLength = file.ContentLength; //获取文件大小
            int thePosition = thefiledir.LastIndexOf('\\');//处理
            string thefilename = thefiledir.Substring(thePosition + 1);//获取文件名
            string fileExt = System.IO.Path.GetExtension(file.FileName).ToLower().Trim();//扩展名

            if (this._FileLength < theFileLength)//判断文件大小
            {
                response = "800403";
                return response;
            }
            this._FileLength = theFileLength;//文件大小


            if (!FileExtensions(fileExt))//判断文件名是否合法
            {
                response = "800404";
                return response;
            }



            string SavaFileName;//文件以时间+随即数方式生成
            System.DateTime currentTime = new DateTime();
            currentTime = System.DateTime.Now;
            SavaFileName = currentTime.ToString();
            SavaFileName = SavaFileName.Replace(" ", "");
            SavaFileName = SavaFileName.Replace("-", "");
            SavaFileName = SavaFileName.Replace(":", "");
            SavaFileName = SavaFileName.Replace("/", "");

            SavaFileName = SavaFileName + "-" + TypeParse.RandomNum(8).ToString();

            FileFSO fso = new FileFSO();
            fso.createDirectory(SavafilePath);//目录过程
            file.SaveAs(SavafilePath + "/" + SavaFileName + fileExt);//保存

            this._FileExt = fileExt.Trim();
            this._FileName = SavaFileName.Trim();


            return response;
            */
        }
        #endregion
    }

}